<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
   <div id="app"></div>
</body>
<script>
    let obj = {}
    function defineReactive(obj,key,value){
        Object.defineProperty(obj,key,{
            get(){
                console.log("获取到了get的值",value)
                return value
            },
            set(newvalue){
                if(newvalue !==value){
                    value = newvalue
                    console.log('执行到了set的值',value)
                    update(value)
                }
                
            }
        })
    }
    function update(val) {
      app.innerText = val
    }
    defineReactive(obj,'name')
    obj.name = "liujinxuan"
</script>
</html>